package com.ruoyi.schoolSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.schoolSys.domain.Cookbook;
import com.ruoyi.schoolSys.service.ICookbookService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜谱管理Controller
 * 
 * @author ruoyi
 * @date 2024-02-12
 */
@RestController
@RequestMapping("/schoolSys/cookbook")
public class CookbookController extends BaseController
{
    @Autowired
    private ICookbookService cookbookService;

    /**
     * 查询菜谱管理列表
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:cookbook:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cookbook cookbook)
    {
        startPage();
        List<Cookbook> list = cookbookService.selectCookbookList(cookbook);
        return getDataTable(list);
    }

    /**
     * 导出菜谱管理列表
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:cookbook:export')")
    @Log(title = "菜谱管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cookbook cookbook)
    {
        List<Cookbook> list = cookbookService.selectCookbookList(cookbook);
        ExcelUtil<Cookbook> util = new ExcelUtil<Cookbook>(Cookbook.class);
        util.exportExcel(response, list, "菜谱管理数据");
    }

    /**
     * 获取菜谱管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:cookbook:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cookbookService.selectCookbookById(id));
    }

    /**
     * 新增菜谱管理
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:cookbook:add')")
    @Log(title = "菜谱管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cookbook cookbook)
    {
        return toAjax(cookbookService.insertCookbook(cookbook));
    }

    /**
     * 修改菜谱管理
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:cookbook:edit')")
    @Log(title = "菜谱管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cookbook cookbook)
    {
        return toAjax(cookbookService.updateCookbook(cookbook));
    }

    /**
     * 删除菜谱管理
     */
    @PreAuthorize("@ss.hasPermi('schoolSys:cookbook:remove')")
    @Log(title = "菜谱管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cookbookService.deleteCookbookByIds(ids));
    }
}
